<template>
<div>
<el-dialog
  title="提示"
  :visible="dialogVisible"
  width="30%"
  :before-close="handleClose">
  <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="类别"  prop='class' :rules="[{
      required: true, message: '类别不能为空', trigger: 'blur'
    }]"
    >
    <el-input v-model="form.class"></el-input>
  </el-form-item>
    <el-form-item label="名称"
    prop='title' :rules="[{
      required: true, message: '标题不能为空', trigger: 'blur'
    }]">
    <el-input v-model="form.title"></el-input>
  </el-form-item>
    <el-form-item label="经费预算"
    prop='fund' :rules="[{
      required: true, message: '经费不能为空', trigger: 'blur'
    }]"
    >
    <el-input v-model="form.fund"></el-input>
  </el-form-item>
    <el-form-item label="付款期限"
     prop='date' :rules="[{
      required: true, message: '日期不能为空', trigger: 'blur',
    },{pattern: /^\d{1,4}(-)(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31)$/,message:'请输入正确的日期',trigger: 'blur'}]">
    <el-input v-model="form.date"></el-input>
  </el-form-item>
    <el-form-item label="负责部门"
    prop="department"
    :rules="[{
      required: true, message: '部门不能为空', trigger: 'blur'
    }]">
    <el-input v-model="form.department"></el-input>
  </el-form-item>
    <el-form-item label="申请人"
    prop="proposers"
    :rules="[{
      required: true, message: '部门不能为空', trigger: 'blur'
    }]">
    <el-input v-model="form.proposers"></el-input>
  </el-form-item>
  <!-- <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button>取消</el-button>
  </el-form-item> -->
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="closefrom">取 消</el-button>
    <el-button type="primary" @click="save">确 定</el-button>
  </span>
</el-dialog>
</div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        class: '',
        title: '',
        fund: '',
        date: '',
        department: '',
        proposers: '',
      },
    }
  },

  props: {
    dialogVisible: Boolean,
    n: Number,
    changobj: Object,

  },
  watch: {
    changobj(val) {
      if (!val) {
        this.form = {}
        return
      }
      this.form = val
    },
  },

  methods: {

    closefrom() {
      this.$emit('close')
    },
    save() {
      this.$emit('close')
      this.$emit('save', this.form)

      if (this.n === 0) {
        this.form = {}
      }
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
          this.$emit('close')
        })
        .catch(_ => {})
    },
  },
}
</script>
